
package com.dxjy.demo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * Swagger配置
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

	/**
	 * SpringBoot获取当前环境代码,Spring获取当前环境代码
	 */
	@Value("${spring.profiles.active}")
	private String profiles;


	/**
	 * 配置 Swagger 2
	 * 注册一个 Bean 属性
	 * enable()：是否启用 Swagger，启用后才能在浏览器中进行访问
	 * groupName()：用于配置 API 文档的分组
	 */
	@Bean
	public Docket docket() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.enable(true)
				.groupName("v1")
				.select()
				// 过滤路径
				//.paths(PathSelectors.ant())
				.build();
	}

	private ApiInfo apiInfo() {
		/*作者信息*/
		Contact contact = new Contact("March21Sunny",
				"https://jianz.xyz",
				"892670873@qq.com");
		return new ApiInfo(
				"SpringBoot 前端后端分离脚手架",
				profiles + "环境",
				"v1.0",
				"https://jianz.xyz",
				contact,
				"Apache 2.0",
				"http://www.apache.org/licenses/LICENSE-2.0",
				new ArrayList()
		);
	}


}